home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c++
- Subject: Re: Problem w/ VC 4.1 and the Deadly Diamond
- Date: 22 Mar 1996 01:12:58 GMT
- Organization: Borland International
- Message-ID: <4isuqq$b26@druid.borland.com>
- References: <4iqmgd$fuk@mark.ucdavis.edu>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4iqmgd$fuk@mark.ucdavis.edu>, ez055808@peseta.ucdavis.edu says...
- >
- >The following code doesn't compile under VC 4.1 (or 4.0) (I haven't tried it
- >yet with other compilers):
- >
- >---------------------------------------------------------------
- >class A
- >{
- >public:
- > A() { }
- > virtual ~A() { }
- >};
- >
- >class B: virtual public A
- >{
- >public:
- > B();
- > virtual ~B() { }
- >};
- >
- >B::B(): A()
- >{
- >}
- >
- >class C: virtual public A
- >{
- >public:
- > C();
- > virtual ~C() { }
- >};
- >
- >C::C(): A()
- >{
- >}
- >
- >class D: public B, public C
- >{
- >public:
- > D();
- > virtual ~D() { }
- >};
- >
- >D::D(): B(), C()
- >{
- >}
- >
- >
- >class TestClass: public D
- >{
- >public:
- > TestClass();
- > virtual ~TestClass() { }
- >};
- >
- >TestClass::TestClass(): D()
- >{
- >}
- >
- >
- >void
- >testFunc1(const TestClass t)
- >{
- >}
- >
- >void
- >testFunc2()
- >{
- > TestClass t;
- > testFunc1(t);
- >}
- >
- >void
- >main(void)
- >{
- > testFunc2();
- >}
- >
- >------------------------------------------------------------------
- >The call to testFunc1() gives the following error message:
- >
- >error C2662: '__vbaseDtor' : cannot convert 'this' pointer from 'const class
- >TestClass *' to 'class TestClass *const '
- >
- >If I change the parameter in testFunc1() to a ref, i.e. const TestClass& t,
- >then it compiles fine.
- >
- >Of course, it should be passed by reference; but I don't understand why I'm
- >getting this error. If I un-virtual the inheritance of B and C from A (thus
- >avoiding the deadly diamond, but causing other headaches), then no compiler
- >error.
- >
- >What gives???
-
- The code is legal. BC++ 5.0 compiles it.
-
-